package zisu.qgs.lambda.lambda;

/**
 * @Author: 蔡翔
 * @Date: 2019/10/3 12:09
 * @Version 1.0
 */
@FunctionalInterface
interface IMath{
    int add(int x,int y);
}

@FunctionalInterface
interface IMath2{
    int sub(int x,int y);
}
public class TypeDemo {
    public static void main(String[] args) {
        // 变量类型定义
        IMath iMath = (x,y) -> x+y;

        //数组里
        IMath[] lambdas = {(x,y) -> x+y};

        //强转
        Object objectLambda = (IMath)(x,y) -> x+y;

        //通过返回类型
        IMath iMath1 = createLambda();

        //类型推断
        // 如果有重载，要强制转换类型。
        TypeDemo typeDemo = new TypeDemo();
        typeDemo.test(((IMath)(x, y) -> x+y));
    }
    public void test(IMath math){

    }

    public void test(IMath2 math){

    }

    public static IMath createLambda(){
        return (x,y)->x+y;
    }

}
